package com.sky.mapper.admin;


import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Employee;
import org.apache.ibatis.annotations.*;

/**
 * 持久层
 */
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    /**
     * 新增员工信息
     * @param employee
     * @return
     */
    @Insert("insert into employee(name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            "values " +
            "(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutoFill(value = OperationType.INSERT) //切面 方法增强 插入
    void add(Employee employee);


    /**
     * 分页查询信息
     * @param dto
     * @return
     */
    Page<Employee> get(EmployeePageQueryDTO dto);

    /**
     * 员工修改密码
     * @param OldPassword
     * @param newPassword
     */
    @Update("update employee set password=#{newPassword} where password=#{OldPassword}")
    void xiugai(String OldPassword, String newPassword);


    /**
     * 启用、禁用员工账号
     * @param id
     * @param status
     *  // 方式2：@Param 注解绑定id=id,而不是由myBatis默认分配parm1,parm2,
     *    @Update("update employee set status=#{status} where id=#{id}")
     *    void offNo(@Param("id") Long id, @Param("status") Integer status);
     */
    void offNo(Integer status,Long id);

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    Employee getById(Long id);



}
